<?php

namespace app\test630\controller;

use app\test630\model\User;
use think\Controller;
use think\Request;
use think\Session;

class Login extends Controller
{
    /**
     *Method index
     *user:登录页面
     *time:2021/6/30 8:37
     */
    public function index()
    {
        return view('');
    }


    /**
     * 处理登录信息
     *Method loginDo
     *user:大飞
     *time:2021/6/30 8:42
     */
    public function loginDo(Request $request)
    {

        $data = $request->param();


        $data['password']=md5(md5($data['password']));

       $res =  User::where('username',$data['username'])->find();


       if ($res)
       {
           if ($res['password'] != $data['password'])
           {
               return $this->error('账号或密码错误','index');
           }

           //存入用户信息
           \session('r_id',$res['r_id']);
           \session('userInfo',$res);
           return $this->redirect('Cuo/index');
       }else{
           return $this->error('账号或密码错误','index');
       }

    }


    /**
     * 退出登录
     *Method loginOut
     *user:大飞
     *time:2021/6/30 9:10
     */
    public function loginOut()
    {
        \session('r_id',null);
        \session('userInfo',null);

        return redirect('index');
    }
}
